package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.config.CommonResult;
import com.neuedu.yyzx.entity.Food;
import com.neuedu.yyzx.entity.Foodie;
import com.neuedu.yyzx.service.IFoodieService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第7组....
 * @since 2021-04-28
 */
@RestController
@RequestMapping("//foodie")
public class FoodieController {
    @Autowired
    IFoodieService foodieService;

    @RequestMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNo , @RequestParam(defaultValue = "10")Integer pageSize, Foodie foodie){
        QueryWrapper queryWrapper =new QueryWrapper();
        if (foodie!=null && StringUtils.isNotEmpty(foodie.getName())){
            queryWrapper.like("name",foodie.getName());
        }
        return CommonResult.success(foodieService.page(new Page<>(pageNo,pageSize),queryWrapper));
    }
    @RequestMapping("/add")
    CommonResult add(Foodie foodie){
        return CommonResult.success(foodieService.saveOrUpdate(foodie));
    }

    @RequestMapping("/update")
    CommonResult update(Foodie foodie){
        return CommonResult.success(foodieService.updateById(foodie));
    }
    @RequestMapping("/getById")
    CommonResult getById(Integer id){
        return CommonResult.success(foodieService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del(Integer id){
        return CommonResult.success(foodieService.removeById(id));
    }

}
